<script type="text/javascript">
	function doSearchOrder(value) {
		
	}
	
	//表格查询  
	function reloadOrder() {
		var params = order_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		order_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		order_list.datagrid('unselectAll');
		order_list.datagrid('uncheckAll');
	}


	function addOrder() {
		createFromWindow("新增信息", "order.do?editOrder", "order.do?saveOrder",
				function(data) {
					reloadOrder();
				});
	}
	
	function deleteOrder() {
		var rows = order_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('order.do?deleteOrderItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadOrder();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editOrder() {
		var rows = order_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			createFromWindow("编辑信息", "order.do?editOrder&orderId=" + rows[0].id,
					"order.do?saveOrder", function(data) {
						reloadOrder();
					},true);
		} else {
			showMsg('请选择操作记录.');
		}

	}
	//查看订单信息
	function lookOrder() {
		var rows = order_list.datagrid('getChecked');
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
// 			createFromWindow("查看信息", "order.do?editOrder&orderId=" + rows[0].id,
// 					"order.do?saveOrder", function(data) {
// 						reloadOrder();
// 					},true);
// 			createFromWindowOptions({
// 				title:"查看信息",
// 				maximizable:false,
// 				href:"order.do?editOrder&orderId=" + rows[0].id,
// 				callback:null,
// 				enableSaveButton:false
// 			});
			createFromWindow("查看信息", "order.do?editOrder&orderId=" + rows[0].id,
					null, null,false);
		} else {
			showMsg('请选择操作记录.');
		}
	}
	
	//审核通过订单
	function passOrder() {
		var rows = order_list.datagrid('getChecked');
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			$.ajax({
           	  	type: 'POST',
           	    dataType:'json',
           	  	url: "order.do?passOrder&orderId=" + rows[0].id,
           	  	success: function(result) {
           	  		printLog(result);
	           	  	if (result.success){
	                	reloadOrder();    
	                }
	                showMsg(result.msg);
           	  	}
           	});
		} else {
			showMsg('请选择操作记录.');
		}
	}
	
	//设置订单无效
	function voidOrder() {
		var rows = order_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要设置订单成无效吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('order.do?voidOrders',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadOrder();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	//操作按钮触发
	function operationsLookOrder(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = order_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("查看信息", "order.do?editOrder&orderId=" + id,
					null, null,false);
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditOrder(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = order_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("编辑消息信息", "order.do?editOrder&id=" + id,
					"order.do?saveOrder", function(data) {
						reloadOrder();
					},true);
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsDeleteOrder(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('order.do?deleteOrder', {
						id : id
					}, function(result) {
						if (result.success) {
							reloadOrder(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	
	//审核通过
	function operationsPassOrder(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要审核通过吗?', function(r) {
				if (r) {
					$.ajax({
		           	  	type: 'POST',
		           	    dataType:'json',
		           	  	url: "order.do?passOrder&orderId=" + id,
		           	  	success: function(result) {
			           	  	if (result.success){
			                	reloadOrder();    
			                }
			                showMsg(result.msg);
		           	  	}
		           	});
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	//设置无效
	function operationsVoidOrder(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要设置订单成无效吗?', function(r) {
				if (r) {
					$.post('order.do?voidOrders',{ids:id},function(result){
	                    if (result.success){
	                    	reloadOrder();    
	                    }
	                    showMsg(result.msg);
	                },'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	
	//订单查询
	function orderSearch() {
		setOrderSearchParams(false);
	    reloadOrder(); 
	}
	//清空查询条件
	function clearOrderSearch() {
		$('#orderSearchForm').form('clear');
		setOrderSearchParams(true);
		reloadOrder(); 
	}
	//设置查询参数或清空查询参数
	function setOrderSearchParams(isClear) {
		var fields =$('#orderSearchForm').serializeArray(); //自动序列化表单元素为JSON对象  
		var params = $('#order_list').datagrid('options').queryParams; //先取得 datagrid 的查询参数  
	    $.each(fields, function(i, field){ 
	    	if(isClear) {
	    		delete params[field.name];
	    	}else {
	    		params[field.name] = field.value; //设置查询参数
	    	}
	    });
	    printLog(params);
	}
</script>

<#assign operations = "[\{shiro:'shop:order:refresh',onClick:'operationsLookOrder',src:'plugins/xdtech/images/notes/note.png',title:'查看'},
	   					\{shiro:'shop:order:pass',onClick:'operationsPassOrder',src:'plugins/xdtech/images/notes/note_go.png',title:'审核通过'},
	   					\{shiro:'shop:order:void',onClick:'operationsVoidOrder',src:'plugins/xdtech/images/notes/note_delete.png',title:'订单无效'}
	  				   ]"/>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		
		<@eu.datagrid id="order_list" toolbar="#orderlist_search" idField="id" operations="${operations!}"
			 url="order.do?loadList" rownumbers="true"
			 item="com.xdtech.shop.vo.OrderItem"/>
		
		<div id="orderlist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="orderSearchForm">
					订单编号：<input type="text" name="orderNo" style="width: 150px" />
					订单状态：<select class="easyui-combobox" name="status" style="width:150px;">  
								<option value="">------</option> 
							    <option value="-1">无效</option>  
							    <option value="0">待审核</option>  
							    <option value="1">审核通过</option>
							</select> 
					联系姓名：<input type="text" name="name" style="width: 150px" />
					 <@eu.linkbutton showName="查询" iconCls="icon-search" onclick="orderSearch()"/>
 					 <@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearOrderSearch()"/>
				</form>
			</div>
			<div id="order_toolbar" style="height: auto">
				
<!-- 				<@eu.linkbutton showName="新增" shiro="shop:order:add" iconCls="icon-add" onclick="addOrder()"/> -->
<!-- 				<@eu.linkbutton showName="删除" shiro="shop:order:delete" iconCls="icon-remove" onclick="deleteOrder()"/> -->
<!-- 				<@eu.linkbutton showName="编辑" shiro="shop:order:edit" iconCls="icon-edit" onclick="editOrder()"/> -->
				<@eu.linkbutton showName="查看" shiro="shop:order:look" iconCls="icon-edit" onclick="lookOrder()"/>
				<@eu.linkbutton showName="审核通过" shiro="shop:order:pass" iconCls="icon-remove" onclick="passOrder()"/>
				<@eu.linkbutton showName="审核无效" shiro="shop:order:void" iconCls="icon-remove" onclick="voidOrder()"/>
				<@eu.linkbutton showName="刷新" shiro="shop:order:refresh" iconCls="icon-reload" onclick="reloadOrder()"/>
				
			</div>
		</div>
	</div>
</div>